<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.util.*,
com.brother.model.*,com.ibatis.common.util.*,org.apache.commons.lang.*"   pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ include file="international.jsp" %> 

<jsp:useBean id="userService" class="com.brother.service.UserService"></jsp:useBean>

<%

com.brother.model.Customer loginUser = (com.brother.model.Customer)session.getAttribute(com.brother.Constants.LOGIN_SESSTION_NAME);
if(loginUser ==null){
	return;
}



%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title><fmt:message key="manage.title.users"/> - <fmt:message key="company.name"/></title>
<link rel="stylesheet" type="text/css"  href="style.css" />
<link rel="stylesheet" type="text/css" href="css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="css/grid-examples.css" />
<style type="text/css">
.whitebg{
	background-color: #ffffff;
}
body{
background-color:#FFFFFF;
}
</style>

    <script type="text/javascript" src="js/ext-base.js"></script>
    <script type="text/javascript" src="js/ext-all.js"></script>
    
    <script type="text/javascript" src="js/search.js"></script>
    <script type="text/javascript" src="js/userList.js?v=1"></script>
    <script type="text/javascript" src="./js/common.js"></script>
    
</head>
<body >
<script>
var waitingMsg = '<fmt:message key="waiting.msg"/>';
var waitingProgressText = '<fmt:message key="waiting.loading"/>';
var search_select_user='<fmt:message key="search.select.user"/>';
var currentUserid = '<%=loginUser.getUserid()%>';
function del_user()
{

	var userids = document.getElementsByName("userid");

	var url = "users.jsp?action=delete";
	var datas =manageUsersGrid.getSelectionModel().getSelections();

	for(var i = 0; i < datas.length; i++){
		//if(trackerIds[i].checked)
		if(currentUserid == datas[0].data.userid){
			//alert("<fmt:message key="manage.users.delete.self"/>");
			Ext.MessageBox.alert('',"<fmt:message key="manage.users.delete.self"/>");
			return;
		}
		url = url + '&userid='+datas[0].data.userid;
	}
	
	if(url.indexOf("userid") == -1){
		//alert("<fmt:message key="manage.users.select"/>");
		Ext.MessageBox.alert('',"<fmt:message key="manage.users.select"/>");
		return;
	}

	Ext.MessageBox.confirm('', '<fmt:message key="manage.user.delete.confirm"/>', function(btn){
		if(btn == 'yes'){
			//window.location.href=url;
			window.location.href=url;
		}
	});
	
	
	
	return;
}

function onModify(){

	var userids = document.getElementsByName("userid");

	var datas =manageUsersGrid.getSelectionModel().getSelections();
	
	var url = "edituser.jsp?carModelId=";
	var selected = false;
	

	if(datas.length == 1){
		url = url + '&userid='+datas[0].data.userid;
		selected = true;
	}else if(datas.length > 1){
		//alert(mutilpleSelectError);
		Ext.MessageBox.alert('',mutilpleSelectError);
		return;
	}
	
	if(!selected){
	 	//alert("<fmt:message key="manage.users.select"/>");
	 	Ext.MessageBox.alert('',"<fmt:message key="manage.users.select"/>");
		return;
	}
	window.location.href=url;
}

var userNameTitle = '<fmt:message key="user.name"/>';
var userIDTitle = '<fmt:message key="user.id"/>';
var emailTitle = '<fmt:message key="user.email"/>';
var supervisorTitle = '<fmt:message key="user.supervisor"/>';
var adminTitle = '<fmt:message key="user.admin"/>';
var descTitle = '<fmt:message key="user.description"/>';
var displayMsg = '<fmt:message key="user.list.display.msg"/>';
var emptyMsg = '';//'<fmt:message key="user.list.empty.msg"/>';
var beforePageText = '<fmt:message key="beforePageText"/>';
var showPreview = '<fmt:message key="show.preview"/>';
var yes = '<fmt:message key="user.admin.yes"/>';
var no = '<fmt:message key="user.admin.no"/>';

Ext.onReady(function(){
	Ext.MessageBox.buttonText.yes = '<fmt:message key="button.yes.text"/>';
	Ext.MessageBox.buttonText.no = '<fmt:message key="button.no.text"/>';
	Ext.MessageBox.buttonText.cancel = '<fmt:message key="button.cancel.text"/>';
	
	top.ajustProducts('<fmt:message key="manage.users"/>', 850, 550,20);
});

</script>
<table width="100%" border="0" cellpadding="0" cellspacing="0">


<tr valign="top">
	<td  align="left" style="padding-left:8px; padding-right:8px;">

<table width="100%" align="left">
	<tr valign="top">
		<td align="left">
			<table  width="100%" align="left">
				<tr>
					<td style="width:25%;padding-right:0px;" align="left">
					<table class="tableNoBorder" >
					<tr>
					<td><div id="addbtn"></div></td>
					<td><div id="delbtn"></div></td>
					<td><div id="modifybtn"></div></td>
					<td><div id="exportbtn"></div></td></tr></table>
					<script type="text/javascript">
						Ext.onReady(function(){
							
						var button = new Ext.Button({renderTo:'addbtn',type:'button', 
							text:'<fmt:message key="manage.user.add"/>',split: true,width:80,
							enableToggle:false});
						button.on('click',function(){
							window.location.href = 'edituser.jsp';
							});
						button = new Ext.Button({renderTo:'delbtn',type:'button', 
							text:'<fmt:message key="manage.delete"/>',split: true,width:80,
							enableToggle:false});
						button.on('click',function(){
							del_user();
							});
						button = new Ext.Button({renderTo:'modifybtn',type:'button', 
							text:'<fmt:message key="manage.modify"/>',split: true,width:80,
							enableToggle:false});
						button.on('click',function(){
							onModify();
							});
						button = new Ext.Button({renderTo:'exportbtn',type:'button', 
							text:'<fmt:message key="report.export.excel"/>',split: true,width:80,
							enableToggle:false});
						button.on('click',function(){
							searchUsers(true);
							});
						
							});
					</script>
					</td>
					<td style="width:70%" align="left">
					<form id="searchForm" action="users.jsp" method="post">
					<input type="hidden" value="search" name="action"/>
					<table class="tableNoBorder" ><tr>
					<td><input type="text" name="userName" value="" id="userAutocomplete" style="width:100px"/></td>
					
					<td id='searchBtn'>
					<script type="text/javascript">
						Ext.onReady(function(){
						var button = new Ext.Button({renderTo:'searchBtn',type:'button', 
							text:'<fmt:message key="manage.search"/>',split: true,width:120,
							enableToggle:false});
						button.on('click',function(){
							searchUsers();
							});
							});
					</script>
					</td>
					</tr>
					</table>
					</form>
						
						
										
					</td>
				</tr>

								
				<tr>
					<td colspan="2" width="100%" id="grid-container">

					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>

	</td>
</tr>

</table>
</body>
</html>
<%
com.brother.database.DataBase.closeThreadConnection();
%>